package com.storm.axactivity.service;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import com.actionbarsherlock.app.SherlockActivity;
import com.storm.axactivity.R;
import com.storm.axactivity.service.ServiceHelper.myLocalBinder;

public class ServiceTest extends SherlockActivity {

	ServiceConnection mSc = null;
	ServiceHelper sHelper = null;
	boolean mIsBind= false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.service_test);

		
		mSc = new ServiceConnection(){
			@Override
			public void onServiceConnected(ComponentName name, IBinder service) {
				// TODO Auto-generated method stub
				//((myLocalBinder)service).getService();
				sHelper = ((myLocalBinder)service).getService();
				Log.d("test","onServiceConnected");
			}
			@Override
			public void onServiceDisconnected(ComponentName name) {
				// TODO Auto-generated method stub
				
			}
        }; 
        Intent service = new Intent(this.getApplicationContext(),ServiceHelper.class);
        this.bindService(service, mSc, Context.BIND_AUTO_CREATE);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Intent service = new Intent(this.getApplicationContext(),ServiceHelper.class);
		bindService(service, mSc, Context.BIND_AUTO_CREATE);
		mIsBind = true;
		Log.d("test","bindService");
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		if(mIsBind)
		{
			Log.d("test","unbindService");
			unbindService(mSc);
			mIsBind = false;
		}
	}
	
}
